#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//#define LOCAL

bool cmp(pair<int,char> x, pair<int, char> y){
    return x.first>y.first ||((x.first== y.first) && x.second<y.second);
}
int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    int T, M, N;
    cin >> T;
    while(T--){
        cin >> M >> N;
        vector<vector<int> > cnt(4, vector<int>(1000));
        for(int i=0; i<M; i++){
            for(int j=0; j<N; j++){
                char ch;
                cin >> ch;
                switch(ch){
                    case 'A':{
                        cnt[0][j]++;
                        break;
                    }
                    case 'C':{
                        cnt[1][j]++;
                        break;
                    }
                    case 'G':{
                        cnt[2][j]++;
                        break;
                    }
                    case 'T':{
                        cnt[3][j]++;
                        break;
                    }
                    default : cout << "error";
                }
            }
        }
        string s; int ans = 0;
        for(int i=0; i<N; i++){
            vector<pair<int, char> > find;
            find.emplace_back(cnt[0][i], 'A');
            find.emplace_back(cnt[1][i], 'C');
            find.emplace_back(cnt[2][i], 'G');
            find.emplace_back(cnt[3][i], 'T');
            sort(find.begin(), find.end(), cmp);
            s.push_back(find[0].second);
            ans += find[1].first +find[2].first + find[3].first;
        }
        cout << s << endl;
        cout << ans << endl;
    }
    return 0;
}
/*
3
5 8
TATGATAC
TAAGCTAC
AAAGATCC
TGAGATAC
TAAGATGT
4 10
ACGTACGTAC
CCGTACGTAG
GCGTACGTAT
TCGTACGTAA
6 10
ATGTTACCAT
AAGTTACGAT
AACAAAGCAA
AAGTTACCTT
AAGTTACCAA
TACTTACCAA

 */